use std::{ future::Future, thread, time::Duration};

use tokio::{runtime::Builder,fs,time::sleep};


//#[tokio::main]
fn main() {


    let handler = thread::spawn(|| {
        // println!("Hello, world!");
        // how to execute future?
        let rt = Builder::new_current_thread()
        .enable_all()
        .build().unwrap();



        rt.spawn(async {
            println!("future 1");

            let content = fs::read_to_string("Cargo.toml").await.unwrap();

            println!("content len {}", content.len())
        });


        rt.spawn(async {
            let ret = expensive_blocking_task("Future2".to_string());
            println!("ret => {}",ret);
        });


        rt.block_on(async {

            sleep(Duration::from_millis(3000)).await;
            //thread::sleep(Duration::from_millis(9000));
          //  println!("hello world  22");
        });
    });

    handler.join().unwrap();
    // let a =10;
    // let b = 20;
    // println!("{} +{} ={}",a,b,a+b);
    

    // return tokio::runtime::Builder::new_multi_thread()
    // .enable_all()
    // .build()
    // .expect("Failed building the Runtime")
    // .block_on(body);

    

//     let c = b;
//     println!("{} +{} = {}", b,c , b+c);

//     let s = String::from("hello");
//     print!("{}",s);
//     let s1 = s.clone();
//   //  print!("{}",s);

}


fn expensive_blocking_task(s: String) -> String{
    thread::sleep(Duration::from_secs(3));
    blake3::hash(s.as_bytes()).to_string()
    
}